﻿//-------------------------------------------------------------------------
///-----------------_类的设计模式------------------------------------------
///-----------------_类的单例模式------------------------------------------
///-----------------2021/5/8---by mky.蒙克雨-------------------------------
//-------------------------------------------------------------------------
#pragma once

//-------------------------------------------------------------------------
#ifndef _CLASS_PROMGR_H
#define _CLASS_PROMGR_H

//-------------------------------------------------------------------------
#include "mqtt_session.h"
#include "mqtt_client.hpp"
//-------------------------------------------------------------------------
namespace mky
{
    //----------------------------------------------
    class ProMgr
    {
    public:
        //----------------------------------------------
        /// 单例模式（Singleton)
        ///  1.  _不能使用new创建对象，也不能直接定义类变量
        ///  2.  _至少需要提供一个静态的方法，用于返回唯一的对象实例
        //----------------------------------------------
        static ProMgr* getSingleton(void);
        static void destroyInstance(void);

        MqttClient<mqttSession>* getMqttClient() {
            if (m_pMqttClient == nullptr) {
                m_pMqttClient = new MqttClient<mky::mqttSession>();
            }
            return m_pMqttClient;
        };
        //----------------------------------------------
    private:
        ProMgr();
        ProMgr(const ProMgr&);

    private:
        static ProMgr* _ProMgr;///_对外实例
        MqttClient<mqttSession>* m_pMqttClient = nullptr; ///mqtt msg client

        //-------------------------------------------------
    };

    //----------------------------------------------
}

//----------------------------------------------
#endif //!_CLASS_PROMGR_H
